﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using TImSdk;

namespace ElabService
{
    public partial class TimService : ServiceBase
    {
        public TimService()
        {
            InitializeComponent();
        }
        string filePath = $@"F:\\MyServiceLog-{DateTime.Now.ToString("yyyyMMdd")}.txt";
        protected override void OnStart(string[] args)
        {

            if (!File.Exists(filePath))
                File.Create(filePath).Close();
            //TImSdkService.SetConfigJsonPath(args[0]);
            var result = TImSdkService.GetInstance.InitTImSdk();
            using (FileStream stream = new FileStream(filePath, FileMode.Append))
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine($"{DateTime.Now}-----------------configJsonPath----------------{Environment.CurrentDirectory}\\Config.json");
                writer.WriteLine($"{DateTime.Now}-----------------服务启动！");
                 writer.WriteLine($"{DateTime.Now}-------------------TImSdkService.InitTImSdk {result.Code},{result.Message}！");
            }


        }

        protected override void OnStop()
        {
            var result = TImSdkService.GetInstance.UnInitTImSdk();
            using (FileStream stream = new FileStream(filePath, FileMode.Append))
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine($"{DateTime.Now},服务停止！");
                writer.WriteLine($"{DateTime.Now}-------------------TImSdkService.UnInitTImSdk {result.Code},{result.Message}！");
            }
        }
    }
}
